package com.zhuiyun.project.api.sysUser.mapper;

import com.zhuiyun.project.api.sysUser.entiy.SysUser;
import com.zhuiyun.project.api.sysUser.model.SysUserModel;
import com.zhuiyun.project.common.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @ClassName SysUserMapper
 * @Description TODO
 * @Author zcy
 * @Date 2023/3/27 10:46
 **/
@Mapper
public interface SysUserMapper extends BaseMapper<SysUser> {
    @Update("update sys_user set amount = amount + #{sysUserModel.amount} where phone = #{sysUserModel.phone}")
    int updateUserAmountByPhone(@Param("sysUserModel") SysUserModel sysUserModel);

    @Update("update sys_user set amount = amount - #{sysUserModel.amount} where phone = #{sysUserModel.phone}")
    int updateUserAmountByPhoneConsume(@Param("sysUserModel") SysUserModel sysUserModel);

    @Select("select amount from sys_user where phone = #{sysUserModel.phone}")
    SysUser selectAmountByPhone(@Param("sysUserModel") SysUserModel sysUserModel);

    @Select("<script>" +
            "SELECT * from  sys_user where  is_del=0 " +
            "<when test = 'userName != &quot;&quot; and userName != null'>" +
            " and user_name LIKE CONCAT('%', #{userName}, '%')  </when>" +
            "</script> ")
    List<SysUserModel> selectSysUser(@Param("userName")String userName);

    @Select("select * from sys_user where id = #{id} and is_del=0")
    SysUser selectUserById(@Param("id") Integer id);

    /**
     * 扣费
     * @param id
     * @param commission
     * @return
     */
    @Update("  UPDATE sys_user " +
            "    SET amount = amount - #{commission} " +
            "    WHERE id = #{id} AND amount >= #{commission}")
    int updateUserAmount(Integer id, BigDecimal commission);

    /**
     * 存入admin账户
     * @param id
     * @param commission
     * @return
     */
    @Update("  UPDATE sys_user " +
            "    SET amount = amount + #{commission} " +
            "    WHERE id = #{id}")
    int updateAdminAmount(Integer id, BigDecimal commission);

    /**
     * 存入根据手机号入账
     * @param phone
     * @param commission
     * @return
     */
    @Update("  UPDATE sys_user " +
            "    SET amount = amount + #{commission} " +
            "    WHERE phone = #{phone}")
    int updateAmountByPhone(String  phone, BigDecimal commission);
}
